<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="com.shsh.safemanage.dao.TitlePostManageGroupDao"%>
<%@page import="java.util.Calendar"%>
<%@page import="com.shsh.safemanage.dao.DepartmentDao"%>
<%@page import="com.shsh.safemanage.model.Department1"%>
<%@page import="com.shsh.safemanage.model.ProblemTransfer"%>
<%@page import="com.shsh.safemanage.model.ProblemTransferFeedback"%>
<%@page import="java.util.List"%>
<%@page import="com.shsh.safemanage.model.Problem"%>
<%@page import="com.shsh.safemanage.model.User"%>
<%@page import="com.shsh.safemanage.model.Role"%>
<%@page import="com.shsh.safemanage.model.JobPost"%>
<%@page import="com.shsh.safemanage.model.Defect"%>
<%@page import="com.shsh.safemanage.model.DefectType"%>
<%@page import="com.shsh.safemanage.dao.DaoCreator"%>
<%@page import="com.shsh.safemanage.dao.ProblemDao"%>
<%@page import="com.shsh.safemanage.action.ActionCreator"%>
<%@page import="com.shsh.safemanage.action.WriteProblemAction"%>
<%@page import="com.shsh.safemanage.action.UserAction"%>
<%@page import="com.shsh.safemanage.util.Constants"%>
<%@page import="com.shsh.safemanage.util.Util"%>

<%
session.removeAttribute(Constants.SESSION_ESCALATE_USER);
session.removeAttribute(Constants.SESSION_MANAGE_GROUP_USER);
session.removeAttribute(Constants.SESSION_PROBLEM_DEPARTMENT1);

DepartmentDao departmentDao = DaoCreator.createDepartmentDao();
ProblemDao problemDao = DaoCreator.createProblemDao();

String fromPage = request.getParameter(Constants.REQUEST_PARAMETER_FROM_PAGE);


TitlePostManageGroupDao titlePostManageGroupDao = DaoCreator.createTitlePostManageGroupDao();
WriteProblemAction writeProblemAction = ActionCreator.createWriteProblemAction();
UserAction userAction = ActionCreator.createUserAction();

List<DefectType> defectTypeList = problemDao.getDefectTypeList();

String initDateEndStr = Util.formatDate(Calendar.getInstance().getTime());

User user = (User) session.getAttribute(Constants.SESSION_USER);
JobPost post1 = titlePostManageGroupDao.getJobPostByID(user.getJobPost1ID());
JobPost post2 = titlePostManageGroupDao.getJobPostByID(user.getJobPost2ID());
JobPost post3 = titlePostManageGroupDao.getJobPostByID(user.getJobPost3ID());
Role theRole = userAction.getUserRole(request);

int role = writeProblemAction.calRole(post1, post2, post3, theRole);

%>
<div class="hider" id="hider">
	<span>&nbsp;</span>
</div>
<div class="position">
	<img src="images/position2.jpg" style="padding: 7px 9px; float: left;" />当前位置：上海高桥分公司问题管理平台 &gt;&gt; 填报
</div>

<div class="tt">《高桥石化公司》</div>
<div class="content">
	<table align="center" border="1" width="99%" cellpadding="0"
		cellspacing="0">
		<tr>
			<td class="td1" colspan="2">
				<span style="margin-left: 30px; font-weight: bold">作业部（业务中心）：</span> <span><%@include file="/depart_select/depart1_shiyebu_select_section.jsp"%></span>
				<span style="margin-left: 30px; font-weight: bold">装置：</span> <span id="equipOfDepartSpan"><%@include file="/equip_select/equipment_of_depart_select_section.jsp"%></span>
				<span style="margin-left: 30px; font-weight: bold">其他报告类型：</span>
				<span>
					<select id="defectType">
						<option value="0" selected="selected">请选择类型</option>
					<%for (DefectType defectType : defectTypeList) {%>
						<option value="<%=defectType.getId()%>"><%=defectType.getDefectType()%></option>
					<%} %>
					</select>
				</span>
			</td>
		</tr>
	<tr>
			<td class="td1" width="60%">			
				<span style="margin-left: 30px; font-weight: bold">其他报告名称：</span>  <br/>
				<span style="margin-left: 30px; ">
						<textarea rows="3" style="width:90%;" id="problemTitle"></textarea>	
				</span>	
			</td>
			<td  class="td1" width="40%">
				<span style="margin-left: 30px; font-weight: bold">其他报告发生时间：</span>
				<input  style="margin-left: 5px; " type="text" id="writeDate" size="15" onfocus="WdatePicker({maxDate:'#F{\'2050-12-31\'}'})" value="<%=initDateEndStr%>"/>
			</td>	
	</tr>
	<tr>
		<td class="td1" colspan="2"><span
			style="margin-left: 30px; font-weight: bold">其他报告经过：</span> <br/>
			<span style="margin-left: 30px; ">
			<textarea rows="5" style="width:90%;" id="problemContent" style="text-align:left;"></textarea>	
			</span>
		</td>
	</tr>
	<tr>
		<td class="td1" colspan="2"><span
			style="margin-left: 30px; font-weight: bold">直接经济损失与间接经济损失：
			</span> 
			<br/>
			<span style="margin-left: 30px; ">
			<textarea rows="5" style="width:90%;" id="loss"></textarea>	
			</span>
		</td>
	</tr>
	<tr>
		<td class="td1" colspan="2"><span
			style="margin-left: 30px; font-weight: bold">其他报告原因分析：
			</span> 
			<br/>
			<span style="margin-left: 30px; ">
			<textarea rows="10" style="width:90%;" id="reason"></textarea>	
			</span>
		</td>
	</tr>
	<tr>
		<td class="td1" colspan="2"><span
			style="margin-left: 30px; font-weight: bold">其他报告教训及防范措施：
			</span> 
			<br/>
			<span style="margin-left: 30px; ">
			<textarea rows="10" style="width:90%;" id="zhenggai_cuoshi"></textarea>	
			</span>
		</td>
	</tr>
	<tr>
		<td class="td1" colspan="2"><span
			style="margin-left: 30px; font-weight: bold">其他报告责任分析及处理情况：
			</span> 
			<br/>
			<span style="margin-left: 30px; ">
			<textarea rows="10" style="width:90%;" id="duty"></textarea>	
			</span>
		</td>
	</tr>
	<tr>
		<td class="td1" colspan="2"><span
			style="margin-left: 30px; font-weight: bold">其他报告调查小组人员名单：
			</span> 
			<br/>
			<span style="margin-left: 30px; ">
			<textarea rows="5" style="width:90%;" id="team"></textarea>	
			</span>
		</td>
	</tr>
		<tr>
			<td class="td1">
				<span style="margin-left: 30px; font-weight: bold">反馈信息：</span>
				<br />
				<div id="feedbackProcessMethodDiv">
				<%@include file="/other/feedback_process_method.jsp" %>
				</div>				
			</td>
		</tr>
		<tr>
			<td class="td1" colspan="2">
				<span style="margin-left: 30px" class="span1">填报人及时间：</span>
				<span><%=user.getDepartment1Name()%>-<%=user.getDepartment2Name()%>-<%=user.getDepartment3Name()%></span>
				<span><%=user.getName()%></span>
				<span><%=Util.formatDateTime(Calendar.getInstance())%></span>
			</td>
		</tr>
		<tr>
			<td class="td1" align="center"  colspan="2">
				<% if(!"postcheckReport".equals(fromPage)) {%>
				<input type="button" value="上报" onclick="convertProblem()" />
				<%} %>
				<input type="button" value="取 消" style="margin-left: 20px" onclick="cancelConvert()" />
			</td>
		</tr>
	</table>
</div>

<script type="text/javascript">
function convertProblem() {	
	var depart1ID = getElementValueByID("depart1");
	var equipID = getElementValueByID("equipID");
	var defectTypeID = getElementValueByID("defectType");
	var problemTitle = getElementValueByID("problemTitle");

	var problemContent = getElementValueByID("problemContent");
	var loss = getElementValueByID("loss");
	var reason = getElementValueByID("reason");
	var zhenggai_cuoshi = getElementValueByID("zhenggai_cuoshi");
	var duty = getElementValueByID("duty");
	var team = getElementValueByID("team");
	
	var processMethod = 0;
	var processRadio3 = document.getElementById('processRadio3');
	if (processRadio3 != null && processRadio3.checked) {
		processMethod = 3;
	} 
	
	if(defectTypeID == 0) {
		$.dialog.alert('请选择其他报告类型');
		return;
	}
	
	if(problemTitle == null || problemTitle == '' || problemTitle == 'undefined') {
		$.dialog.alert('请填写其他报告名称');
		return;
	}
	
	if(reason == null || reason == '' || reason == 'undefined') {
		$.dialog.alert('请填写其他报告原因');
		return;
	}	
	
	
	if(zhenggai_cuoshi == null || zhenggai_cuoshi == '' || zhenggai_cuoshi == 'undefined') {
		$.dialog.alert('请填写其他报告教训及防范措施');
		return;
	}	
	
	if(duty == null || duty == '' || duty == 'undefined') {
		$.dialog.alert('请填写其他报告责任分析及处理情况');
		return;
	}
	
	if(team == null || team == '' || team == 'undefined') {
		$.dialog.alert('请填写其他报告调查小组人员名单');
		return;
	}
	
	if ($.dialog.confirm('您确定上报此问题为其他报告吗？', function(){
		openWaitingDialog('waitingDialog');
		$.ajax({
			type:'post',
			url:'<%=request.getContextPath()%>/other/write_other_process.jsp',
			data:{
				depart1ID: depart1ID,
				equipID: equipID,
				processMethod: processMethod,
				feedback: '',
				defectTypeID: defectTypeID,
				problemTitle: problemTitle,
				problemContent: problemContent,
				loss: loss,
				reason: reason,
				zhenggai_cuoshi: zhenggai_cuoshi,
				duty: duty,
				team: team
			},
			success:function(data,state,xmlhttp){
				var obj = null;
				try {
					obj = eval('(' + data + ')');
				} catch (e) {
				}
				if (typeof(obj.isSuccess) != 'undefined') {
					closeWaitingDialog('waitingDialog');
					if (obj.isSuccess == 'true') {
						$.dialog('其他报告填报成功！', function() { loadPageSection(
								'<%=request.getContextPath()%>/other/other_browse.jsp', 
								'mainContentDiv', 
								{
									fromPage: 'feedback'
								}
							);
						});
					} else {
						$.dialog.alert(obj.error);
					}
				}
			}
		});
	}, function(){}));
}

function cancelConvert() {
	$.dialog.confirm('您确定取消此次输出吗？', function() {
		loadPageSection(
				'<%=request.getContextPath()%>/user_infor.jsp', 
				'mainContentDiv', 
				{
					fromPage:'defect'
				}, 
			true);
	}, function(){});
}


function chooseProcessMethod(method) {
//empty.
	//convertProblem();
}

function selectDepart1() {
	loadPageSection(
			'<%=request.getContextPath()%>/equip_select/equipment_of_depart_select_section.jsp',
			'equipOfDepartSpan', {
				depart1ID : getElementValueByID('depart1')
			}, false, function() {
				document.getElementById('equipID').value = '';
			});
}
</script>
